
use reqwest::blocking::Client;
use serde_json::json;

pub fn http_get() -> Result<(), Box<dyn std::error::Error>> {
  let client = Client::new();
  let response = client.get("http://192.168.79.86:2969/rust/get?rust=1428")
      .send()?;

  if response.status().is_success() {
      let body = response.text()?;
      println!("Response: {}", body);
  } else {
      println!("Request failed with status: {}", response.status());
  }

  Ok(())
}


pub async fn http_post(ds:u32) -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::new();
    let payload = json!({"name": "zy"});

    let response = client.post("http://192.168.79.86:2969/rust/post")
        .json(&payload)
        .send()?;

    if response.status().is_success() {
        let body = response.text()?;
        println!("Response: {}", body);
    } else {
        println!("Request failed with status: {}", response.status());
    }

    Ok(())
}